#include <stdio.h>
#include "ofc/DAvlTree.h"

int main(int argc, char *argv[])
{
  DAvlTree *tree = [DAvlTree alloc];
  DText    *key  = [DText    new  ];
  DText    *val;

  [tree init :[DText class]];            // Init tree, key is a DText object

  [key set :"Key1"];                     // Set key1 and create value1 for tree
  val = [DText new]; [val set :"Value1"];

  [tree insert :key :val];

  [key set :"Key2"];                     // Set key1 and create value1 for tree
  val = [DText new]; [val set :"Value2"];

  [tree insert :key :val];               // Create key2 and value2 for tree

  printf("Number of elements:%ld\n", [tree length]);  // Print tree length

  [key set :"Key2"];
                                         // Check key present
  printf("%s is %s present in tree\n", [key cstring], ([tree has :key] ? "" : "not"));

  val = [tree get :key];
  printf("%s has value %s\n", [key cstring], (val != nil ? [val cstring] : "???"));

  [tree free];                           // Free tree and stored objects
  [key  free];

  return 0;
}


